class Product {
  int? id;
  final int restaurantId; // 外键，关联到饭店
  final String name;
  final String spec; // 规格，如：箱、瓶、斤
  final double currentPrice; // 当前单价

  Product({
    this.id,
    required this.restaurantId,
    required this.name,
    required this.spec,
    required this.currentPrice,
  });

  // 将模型转换为Map，用于存入数据库
  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'restaurant_id': restaurantId,
      'name': name,
      'spec': spec,
      'current_price': currentPrice,
    };
  }

  // 从数据库的Map数据构造一个Product模型
  factory Product.fromMap(Map<String, dynamic> map) {
    return Product(
      id: map['id'],
      restaurantId: map['restaurant_id'],
      name: map['name'],
      spec: map['spec'],
      currentPrice: map['current_price'],
    );
  }

  // 创建一个副本，可用于编辑
  Product copyWith({
    int? id,
    int? restaurantId,
    String? name,
    String? spec,
    double? currentPrice,
  }) {
    return Product(
      id: id ?? this.id,
      restaurantId: restaurantId ?? this.restaurantId,
      name: name ?? this.name,
      spec: spec ?? this.spec,
      currentPrice: currentPrice ?? this.currentPrice,
    );
  }
}